package com.beiing.tianshuai.tianshuai.freshnews.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryIsPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.FreshNewsListBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by magikliu on 2017/7/12.
 */

public class DiscoveryModel implements DiscoveryModelImpl{

    @Override
    public void getDiscoverys(String userid, int page, int num, int picnum, final CallBack callBack) {
        DisposableObserver<FreshNewsListBean> observer = new DisposableObserver<FreshNewsListBean>() {
            @Override
            public void onNext(@NonNull FreshNewsListBean freshNewsListBean) {
                callBack.result(freshNewsListBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getFreshNewsList(userid, page, num, picnum)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void getDiscoveryIsPraise(String u_id, String f_id, final CallBack callBack) {
        DisposableObserver<DiscoveryIsPraiseBean> observer = new DisposableObserver<DiscoveryIsPraiseBean>() {
            @Override
            public void onNext(@NonNull DiscoveryIsPraiseBean discoveryIsPraiseBean) {
                callBack.result(discoveryIsPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryIsPraiseResult(u_id, f_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseDiscovery(String u_id, String f_id, final CallBack callBack) {
        DisposableObserver<DiscoveryPraiseBean> observer = new DisposableObserver<DiscoveryPraiseBean>() {
            @Override
            public void onNext(@NonNull DiscoveryPraiseBean discoveryPraiseBean) {
                callBack.result(discoveryPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDiscoveryPraiseResult(u_id, f_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
